/*
 * Created on Dec 7, 2006
 */
package org.mushroomdb.parser.select;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.mushroomdb.parser.Parser;
import org.mushroomdb.parser.ParserException;
import org.mushroomdb.parser.select.javacc.ParseException;
import org.mushroomdb.parser.select.javacc.SelectParser;
import org.mushroomdb.query.Query;

/**
 * @author Matu
 */
public class SelectParserAdapter implements Parser {

	/**
	 * Default constructor
	 */
	public SelectParserAdapter() {
	}

	/**
	 * @see org.mushroomdb.parser.Parser#parseQuery(java.lang.String)
	 */
	public Query parseQuery(String query) throws ParserException {
		
		/* Obtains the bytes */
		byte[] bytes = query.getBytes();
		
		/* Parses and generates the semantic tree */
		try {
			InputStream is = new ByteArrayInputStream(bytes);
			SelectParser parser = new SelectParser(is);
			parser.start();
			is.close();
		} catch (ParseException e) {
			throw new ParserException(e.getMessage());
		} catch (IOException e) {
			/* We may continue */
		}
		
		// TODO
		return null;
	}

	/**
	 * @see org.mushroomdb.parser.Parser#accepts(java.lang.String)
	 */
	public boolean accepts(String query) {
		return query.trim().toUpperCase().startsWith("SELECT"); //$NON-NLS-1$
	}

}
